package test1;

import java.util.Random;

public class Solution99 {//老鼠喝药问题

    public static void main(String[] args) {
        Random random = new Random();
        int poison = random.nextInt(32);
        System.out.println("poison = " + poison);
        getPoison(poison);
    }

    private static void getPoison(int poison){
        int mouse = 1, id = 1;
        boolean first = true;
        while (poison != 0){
            if ((poison & mouse) != 0){//表示老鼠死掉
                if (first){
                    first = false;
                }else {
                    id = id * 2 + 1;
                }
            }else {
                id = id * 2;
                first = false;
            }
            poison = poison >> 1;
        }
        System.out.println("id = " + id);
    }
}
